package com.xzx.mr.kv;

import lombok.Data;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @author xinzhixuan
 * @version 1.0
 * @date 2024/8/10 18:14
 */
@Data
public class AnalysisKey implements WritableComparable<AnalysisKey> {
    private String phone;
    private String date;

    public static AnalysisKey of(String phone, String date) {
        AnalysisKey analysisKey = new AnalysisKey();
        analysisKey.phone = phone;
        analysisKey.date = date;
        return analysisKey;
    }

    @Override
    public int compareTo(AnalysisKey o) {
        int result = phone.compareTo(o.phone);
        return result == 0 ? date.compareTo(o.date) : result;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(phone);
        out.writeUTF(date);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        phone = in.readUTF();
        date = in.readUTF();
    }
}
